package com.example.startapp.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.example.startapp.R;
import com.example.startapp.entity.Purchase;

import java.util.List;

public class PurchaseAdapter extends ArrayAdapter<Purchase> {
    public PurchaseAdapter(Context context, List<Purchase> purchases){
        super(context, R.layout.test_2,purchases);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.test_2, parent, false);
        }

        Purchase purchase = getItem(position);
        TextView purChaseId =convertView.findViewById(R.id.text_5);
        TextView purChaseComId =convertView.findViewById(R.id.text_6);
        TextView purChaseUserId=convertView.findViewById(R.id.text_7);
        TextView purChaseQuantity= convertView.findViewById(R.id.text_8);

//
        purChaseId.setText(purchase.getPurchaseId() == null ? " " : purchase.getPurchaseId().toString());
        purChaseComId.setText(purchase.getCommodity() == null || purchase.getCommodity().getCommodityId()==null ?  " " : purchase.getCommodity().getCommodityId().toString());
        purChaseUserId.setText(purchase.getUser() == null ||  purchase.getUser().getUserId()==null ? " " :purchase.getUser().getUserId().toString());
        purChaseQuantity.setText(purchase.getQuantity() == null ? " " : purchase.getQuantity().toString());


        return convertView;
    }

}